From 1b2e69f6c08047983bb1873b6cefed4a79a407f5 Mon Sep 17 00:00:00 2001 From: Chun-wei Fan Date: Mon, 8 Nov 2021 15:20:48 +0800 Subject: [PATCH] GDK-Win32: Realize EGL using common realization code This will clean up the EGL code in GDK-Win32, as well as fixing crashes caused by using an invalid EGL context in gdk_gl_context_make_current() as we did not store up the EGL context in the correct place (lost during the transition to the common EGL initialization code). On the Windows/libANGLE side, the initialization of EGL has now fully moved to the common code in GDK, but we will still default on WGL for now. Help is really appreciated for fixing the shaders on libANGLE! --- gdk/win32/gdkglcontext-win32-egl.c | 121 ----------------------------- 1 file changed, 121 deletions(-) diff --git a/gdk/win32/gdkglcontext-win32-egl.c b/gdk/win32/gdkglcontext-win32-egl.c index 72b3381dfd..e953bd9e13 100644 --- a/gdk/win32/gdkglcontext-win32-egl.c +++ b/gdk/win32/gdkglcontext-win32-egl.c @@ -114,124 +114,6 @@ gdk_win32_gl_context_egl_end_frame (GdkDrawContext *draw_context, eglSwapBuffers (gdk_display_get_egl_display (display), egl_surface); } -#define N_EGL_ATTRS 16 - -static EGLContext -create_egl_context (EGLDisplay display, - EGLConfig config, - GdkGLContext *share, - int flags, - int major, - int minor, - gboolean *is_legacy) -{ - EGLContext ctx; - EGLint context_attribs[N_EGL_ATTRS]; - int i = 0; - - /* ANGLE does not support the GL_OES_vertex_array_object extension, so we need to use ES3 directly */ - context_attribs[i++] = EGL_CONTEXT_CLIENT_VERSION; - context_attribs[i++] = 3; - - /* Specify the flags */ - context_attribs[i++] = EGL_CONTEXT_FLAGS_KHR; - context_attribs[i++] = flags; - - context_attribs[i++] = EGL_NONE; - g_assert (i < N_EGL_ATTRS); - - ctx = eglCreateContext (display, - config, - share != NULL ? GDK_WIN32_GL_CONTEXT_EGL (share)->egl_context - : EGL_NO_CONTEXT, - context_attribs); - - if (ctx != EGL_NO_CONTEXT) - GDK_NOTE (OPENGL, g_message ("Created EGL context[%p]", ctx)); - - return ctx; -} - -static gboolean -gdk_win32_gl_context_egl_realize (GdkGLContext *context, - GError **error) -{ - GdkWin32GLContextEGL *context_egl = GDK_WIN32_GL_CONTEXT_EGL (context); - - gboolean debug_bit, compat_bit, legacy_bit; - gboolean use_es = FALSE; - EGLContext egl_context; - EGLContext ctx; - - /* request flags and specific versions for core (3.2+) WGL context */ - int flags = 0; - int major = 0; - int minor = 0; - - GdkSurface *surface = gdk_gl_context_get_surface (context); - GdkWin32Surface *impl = GDK_WIN32_SURFACE (surface); - GdkDisplay *display = gdk_gl_context_get_display (context); - EGLDisplay egl_display = gdk_display_get_egl_display (display); - EGLConfig egl_config = gdk_display_get_egl_config (display); - GdkGLContext *share = gdk_display_get_gl_context (display); - - gdk_gl_context_get_required_version (context, &major, &minor); - debug_bit = gdk_gl_context_get_debug_enabled (context); - compat_bit = gdk_gl_context_get_forward_compatible (context); - - /* - * A legacy context cannot be shared with core profile ones, so this means we - * must stick to a legacy context if the shared context is a legacy context - */ - - /* if GDK_GL_LEGACY is set, we default to a legacy context */ - legacy_bit = GDK_DISPLAY_DEBUG_CHECK (display, GL_LEGACY) ? - TRUE : - share != NULL && gdk_gl_context_is_legacy (share); - - use_es = GDK_DISPLAY_DEBUG_CHECK (display, GL_GLES) || - (share != NULL && gdk_gl_context_get_use_es (share)); - - if (debug_bit) - flags |= EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR; - if (compat_bit) - flags |= EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR; - - GDK_NOTE (OPENGL, g_message ("Creating EGL context version %d.%d (debug:%s, forward:%s, legacy:%s)", - major, minor, - debug_bit ? "yes" : "no", - compat_bit ? "yes" : "no", - legacy_bit ? "yes" : "no")); - - ctx = create_egl_context (egl_display, - egl_config, - share, - flags, - major, - minor, - &legacy_bit); - - if (ctx == EGL_NO_CONTEXT) - { - g_set_error_literal (error, GDK_GL_ERROR, - GDK_GL_ERROR_NOT_AVAILABLE, - _("Unable to create a GL context")); - return FALSE; - } - - GDK_NOTE (OPENGL, g_print ("Created EGL context[%p]\n", ctx)); - - context_egl->egl_context = ctx; - - /* We are using GLES here */ - gdk_gl_context_set_use_es (context, TRUE); - - /* Ensure that any other context is created with a legacy bit set */ - gdk_gl_context_set_is_legacy (context, legacy_bit); - - return TRUE; -} - static void gdk_win32_gl_context_egl_begin_frame (GdkDrawContext *draw_context, gboolean prefers_high_depth, @@ -247,12 +129,9 @@ gdk_win32_gl_context_egl_class_init (GdkWin32GLContextClass *klass) { GdkGLContextClass *context_class = GDK_GL_CONTEXT_CLASS(klass); GdkDrawContextClass *draw_context_class = GDK_DRAW_CONTEXT_CLASS(klass); - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); context_class->backend_type = GDK_GL_EGL; - context_class->realize = gdk_win32_gl_context_egl_realize; - draw_context_class->begin_frame = gdk_win32_gl_context_egl_begin_frame; draw_context_class->end_frame = gdk_win32_gl_context_egl_end_frame; } -- 2.30.2